import ToolVuex from "@/tool/vuex/ToolVuex.js";
import service from "./ToolAxios";
import ToolConfig from "@/tool/ToolConfig"

export default {
	async request(url, data = {}, method = "GET", headers) {
		if (url.indexOf("/") !== 0 && url.indexOf("http") !== 0) {
			url = "/" + url;
		}
		if (url.indexOf("?") < 0) {
			url += `?_t=${new Date().getMinutes()}`
		}
		let _dsId = data._dsId || ToolVuex.state._dsId;
		url += _dsId ? `&_dsId=${_dsId}` : "";
		delete data._dsId;
		
		method = method.toLowerCase();
		let params = { url, method };
		if (method == "get") {
			params.params = data;
		} else {
			params.data = data;
		}
		return service(params)
	},
	get(url, data, headers) {
		return this.request(url, data, headers);
	},
	post(url, data, headers) {
		return this.request(url, data, "POST", headers);
	},
	put(url, data, headers) {
		return this.request(url, data, "PUT", headers);
	},
	delete(url, data, headers) {
		return this.request(url, data, "DELETE", headers);
	}
}
